package com.itheima.model.vo;

import com.itheima.model.domain.Announcement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AnnouncementVo implements Serializable {

    private String id;

    private String title;

    private String description;

    private String createDate;

    public static AnnouncementVo init(Announcement announcement){
        AnnouncementVo vo = new AnnouncementVo();
        vo.setId(announcement.getId().toString());
        vo.setTitle(announcement.getTitle());
        vo.setDescription(announcement.getDescription());

        Date created = announcement.getCreated();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createDate = sdf.format(created);

        vo.setCreateDate(createDate);
        return vo;
    }
}
